<?php

	require_once(dirname(__FILE__)."/../core/safeParam.php");

	class module{
		function Add($vars){
			global $database;
    		$database->insert_array('users', $vars);
    		header("Location: ../admin/index.php?edit=users&updated=1");
    	}
  		
  		function Edit($vars){
  			global $database;
  			$error = "";
  			
  			unset($_SESSION['error']);
  			
  			if (trim($vars['password']) != "") {
  				if ($vars['password_confirm'] != $vars['password'] ) {
  					$error .= "password confirmation does not match password";
  				}
  				
  				if (! $error){ 
  					$vars['password'] = md5($vars['password']);
      		}
      	} else {
      		unset($vars['password']);
      	}
      	
      	unset($vars['password_confirm']);
      	
      	if (!$error) {
      		$results =  $database->update_array('users', $vars, "id = " . $vars['id'] . "");
      		
      		if (!$results) {
      			$_SESSION['error'] = mysql_error();
      		}
      		
    		} else {
      		$_SESSION['error'] = $error;
    		}

    		if (!$_SESSION['error']){
      		header("Location: ../admin/index.php?edit=users&updated=1");
    		} else {
      		header("Location: ../admin/index.php?edit=users");
    		}
  		}
  		
  		function Delete($vars){
    		global $database;
    		$database->delete('users', "id = " . $vars['id'] . "");
    		header("Location: ../admin/index.php?edit=users&updated=1");
  		}
	}
?>
